package coreEngine;

import main.SatelliteTracker;

public class MovingAntenna implements Runnable{
	
	private SatelliteTracker st;
	private double azimuth;
	private double elevation;
	private boolean moveTime;
	
	public MovingAntenna(SatelliteTracker st){
		this.st = st;
		//construtor
		moveTime = false;
		azimuth = 0.0;
		elevation = 0.0;
	}
	
	public void updateAntenna(){
		//enviar novas coordenadas para a antena
	}
	
	public boolean isAboveHorizon(){
		return st.isSatelliteAboveHorizon();
	}
	
	//move para a posicao de inicio - local o satelite vai aparecer no horizonte
	public String startingPosition(){
		return st.getFirstAzimuth() + "_0.0";
	}
	
	//verifica se a antena esta numa determinada posicao
	public boolean checkPosition(double a, double e){
		if(azimuth == a && elevation == e) 
			return true;
		else 
			return false;
	}
	
	public boolean isTimeToStop(){
		if(elevation <= 0.0) 
			return true;
		else 
			return false;
	}
	
	public void movingTime(){
		moveTime = true;
	}
	
	public double getElevation(){
		return elevation;
	}
	
	public double getAzimuth(){
		return azimuth;
	}

	@Override
	public void run() {
		
		while(st.getOrbit().isSatelliteVisible()){
			if(azimuth != st.getOrbit().getAzimtuh())
				azimuth = st.getOrbit().getAzimtuh();
			if(elevation != st.getOrbit().getElevation())
				elevation = st.getOrbit().getElevation();
			st.getArduinoConnector().sendData(azimuth + "_" + elevation);
			try {
				Thread.sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		// TODO Sequencia de acoes a realizar quando e arrancada ate ser terminada

		
	}
	

	

}
